#include "calibration.hpp"

using namespace std;

Cali::Cali(Process *pro, States *_state):Observer(pro)
{
	state = _state;
	inFile.open("data/test.txt");
	char temp;
	
	if(inFile.is_open())
	{
		while(!inFile.eof())
		{
			inFile >> temp;
			if (temp != ':')
				continue;
			else
			{
				int x,y,width,height;
				inFile >> x >> temp >> y >> temp >> width >> temp >> height >> temp;
				I_Rect r(x,y,width,height);
				In_box.push_back(r);
				std::cout << x << "," << y << "," << width << "," << height << std::endl;
			}			
		}
			
	}
	
	outFile.open("test_1.txt");
}

Cali::~Cali()
{
	Log("Release Cali");
	
	_pro->Detach(this);
}

void Cali::Update(const Image &image)
{
	if( state->TrackObject )
	{	
		if (_pro->m_count > t_count)
		{
			state->selection = In_box[t_count];
			t_count = _pro->m_count;
		}
		CaliBox = I_Rect(state->selection.x, state->selection.y, state->selection.width, state->selection.height);
	}
}
